import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import moment from 'moment';
import { deptSimple, userSimple } from '/@/api/backs/foundation/foundation';
export const columns: BasicColumn[] = [
  {
    title: '员工',
    dataIndex: 'userName',
  },
  {
    title: '部门',
    dataIndex: 'deptName',
  },
  {
    title: '考勤月份',
    dataIndex: 'attendanceMonth',
  },
  {
    title: '考勤天数',
    dataIndex: 'attendanceMonthDayCount',
  },
  {
    title: '出勤（天）',
    dataIndex: 'attendanceNormalCount',
  },
  {
    title: '请假（小时）',
    dataIndex: 'attendanceLeaveCount',
  },
  {
    title: '迟到（次）',
    dataIndex: 'attendanceLateCount',
  },
  {
    title: '早退（次）',
    dataIndex: 'attendanceEarlyCount',
  },
  {
    title: '漏签（次）',
    dataIndex: 'attendanceMissCount',
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    label: '员工',
    field: 'userName',
    colProps: { span: 8 },
    component: 'Input',
    componentProps: {
      placeholder: '请输入员工',
    },
  },
  {
    label: '部门',
    field: 'deptId',
    component: 'ApiTreeSelect',
    colProps: { span: 8 },
    componentProps: {
      api: () => deptSimple({}),
      replaceFields: {
        title: 'name',
        key: 'id',
        value: 'id',
      },
      placeholder: '请选择部门',
      dropdownStyle: { maxHeight: '400px', overflow: 'auto' },
      dropdownMatchSelectWidth: true,
      handleTree: 'id',
    },
  },
  {
    field: 'attendanceMonth',
    label: '考勤月份',
    component: 'MonthPicker',
    colProps: { span: 8 },
    componentProps: {
      placeholder: '请选择月份',
      valueFormat: "X"
    },
  },
  // {
  //   label: '项目',
  //   field: 'parentId',
  //   component: 'ApiTreeSelect',
  //   colProps: { span: 8 },
  //   componentProps: {
  //     api: () => getDeptList({}),
  //     replaceFields: {
  //       title: 'name',
  //       key: 'id',
  //       value: 'id',
  //     },
  //     dropdownStyle: { maxHeight: '600px', overflow: 'auto' },
  //     dropdownMatchSelectWidth: true,
  //     handleTree: 'id',
  //   },
  // },
];

export const formSchema: FormSchema[] = [
  {
    field: 'userIds',
    label: '员工',
    component: 'ApiSelect',
    required: ({ values }) =>
      (values.deptIds && values.deptIds.length) || (values.projectId && values.projectId.length)
        ? false
        : true,
    componentProps: {
      api: () => userSimple({}),
      labelField: 'nickname',
      valueField: 'id',
      mode: 'multiple',
      placeholder: '请选择员工',
      getPopupContainer: () => document.body,
      filterOption: (input, option) => {
        return option.label.toLowerCase().indexOf(input.toLowerCase()) >= 0;
      },
    },
    dynamicDisabled: ({ values }) =>
      (values.deptIds && values.deptIds.length) || (values.projectId && values.projectId.length)
        ? true
        : false,
  },
  {
    field: 'deptIds',
    label: '指定部门',
    required: ({ values }) =>
      (values.userIds && values.userIds.length) || (values.projectId && values.projectId.length)
        ? false
        : true,
    component: 'ApiTreeSelect',
    componentProps: {
      placeholder: '请选择部门',
      api: deptSimple,
      labelField: 'name',
      valueField: 'id',
      treeCheckable: true,
      replaceFields: {
        children: 'children',
        title: 'name',
        key: 'id',
        value: 'id',
      },
      showSearch: true,
      filterTreeNode: (inputValue, treeNode) => {
        return treeNode.props.name.toLowerCase().indexOf(inputValue.toLowerCase()) >= 0;
      },
    },
    dynamicDisabled: ({ values }) =>
      (values.userIds && values.userIds.length) || (values.projectId && values.projectId.length)
        ? true
        : false,
  },
  {
    field: 'attendanceMonth',
    label: '考勤月份',
    required: true,
    component: 'MonthPicker',
    componentProps: {
      disabledDate: (currentDate) => {
        return currentDate >= moment().subtract(0, 'month').endOf('month');
      },
      placeholder: '请选择考勤月份',
      valueFormat: 'yyyy-MM',
    },
  },
];
